package com.bo.Service.Impl;


import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bo.Dao.CompanyIntDao;
import com.bo.Entity.CompanyInt;
import com.bo.Entity.MyImage;
import com.bo.Service.CompanyIntService;


@Service
public class CompanyIntServiceImpl implements CompanyIntService{

	@Autowired
	private CompanyIntDao companyIntDao;
	
	
	@Transactional(readOnly=true)
	public CompanyInt getCompanyInt(int companyId){
		
		List<CompanyInt> list=companyIntDao.getCompany(companyId);
		
		if(list.size()==0){
			return null;
		}else{
			
			return list.get(0);
		}
	}
	
	@Transactional
	public boolean saveOrUpdate(CompanyInt companyInt){
		
    	CompanyInt com=this.getCompanyInt(companyInt.getCompanyId());
    	
    	if(com==null){
    		
    		return this.save(companyInt);

    	}else{
    			
    		return this.update(companyInt);
    	}
	}
	
	
	
	@Transactional
	public boolean save(CompanyInt companyInt){
		
		try{
			
		  companyIntDao.save(companyInt);
		  
		  return true;
	    
		}catch(Exception e){
			
			e.printStackTrace();
			return false;
	    }
	}
	
	@Transactional
    public boolean update(CompanyInt companyInt){
		
		int num=companyIntDao.update(companyInt);
		
		if(num>0)
			return true;
		else
			return false;
	}
	
	@Transactional
    public boolean delete(int id){
    	
    	int num=this.companyIntDao.delete(id);
    	
    	if(num>0)
    		return true;
    	else
    		return false;
    }
	
	
	@Transactional(readOnly=true)
	public void getImage(int id, MyImage image){
		
		try{
			
		   companyIntDao.getImage(id, image);
		   
		}catch(EmptyResultDataAccessException e){
			
		}
	}
	
	
}
